﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="cvi_busy_lib.js" />

$(document).ready(function () {
    //menuChange();
    initSmallMenu();
    addSwitch();
    $("#bigmenu").change(function () {
        $.getJSON(appPath + "Home/LoadSmallMenu.aspx/" + $("#bigmenu").val(), { "cid": cId }, function (data, textStatus) {
            $("#smallmenu").empty();
            $.each(data, function (i, itemvalue) {
                $("#smallmenu").append($("<option></option>").val(itemvalue.ChId).html(itemvalue.ChName))
            });
            menuChange();
        });
    })

    $("#smallmenu").change(function () {

        if (cId != this.value && this.value > 0) {
            var url = document.location.href;
            url = url.substring(0, url.indexOf('?')) + "?cId=" + this.value;

            location.href = url;
        }
        menuChange();
    })
})

function initSmallMenu() {
    var bigmenu = $("#bigmenu").val();
    if (bigmenu != "14") {
        $("#smallmenu").css("display", "");
    }
    else
        $("#smallmenu").css("display", "none");
}

function menuChange() {
    try {
        getBusyOverlay(document.getElementById('menu'), { color: '#C0C0C0', opacity: 0.5 });
    }
    catch (e) { }

    var cId;
    if (1 == $("#bigmenu").val()) {
        cId = 1;
    } else if (14 == $("#bigmenu").val()) {
        cId = 60;
    } else {
        cId = $("#smallmenu").val();
    }

    $("#menu").load(
        appPath + "Home/LoadMenu.aspx/" + $("#bigmenu").val(),
        { cid: cId, ed: new Date().getTime() },

        function () { addSwitch(); initSmallMenu(); }
    );
}


function addSwitch() {
    $("div.nav h3").click(function () {
        var s = $("span.switch", this);
        if (s.html() == "-") {
            s.html("+");
        } else {
            s.html("-");
        }
        $(this).parents("li").find("ul").slideToggle('fast');
    });
}
